home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / debug.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  6.3 KB  |  340 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #ifndef EXPORT
  10. #include "ada.h"
  11. #include "adalexprots.h"
  12. #include "reduceprots.h"
  13. #include "pspansprots.h"
  14.  
  15. /*
  16.  *        DEBUGGING PROCEDURES (for use with dbx)
  17.  */
  18.  
  19. char *zkind_str(struct ast *);
  20. int zastcount(struct ast *);
  21.  
  22. void zpdeadnode(struct ast *node)                            /*;zpdeadnode*/
  23. {
  24.     printf("Node 0x%x %d, Kind %d %s\n",node,node,
  25.         node->kind,zkind_str(node));
  26.     printf("link: 0x%x %d\n",((struct tmpnode *)node)->link,
  27.         ((struct tmpnode *)node)->link);
  28. }
  29.  
  30. void zpnod(struct ast *node)                                /*;zpnod*/
  31. {
  32.     short i,n;
  33.     struct two_pool *listptr;
  34.  
  35.     if (node == NULL) {
  36.         printf("node is NULL\n");
  37.         return;
  38.     }
  39.     printf("Node 0x%x %d, Kind %d %s\n",node,node,
  40.         node->kind,zkind_str(node));
  41.     if (isast_node[node->kind]) {
  42.         n = zastcount(node);
  43.         printf("astcount %d     ",n);
  44.         for (i=0; i<n; i++)
  45.             printf("0x%x ",node->links.subast[i]);
  46.         printf("\n");
  47.     }
  48.     else if (islist_node[node->kind]) {
  49.         printf("list: ");
  50.         if (node->links.list != NULL) {
  51.             listptr = node->links.list;
  52.             do {
  53.                 listptr = listptr->link;
  54.                 printf("0x%x ",listptr->val.node);
  55.             } while (listptr != node->links.list);
  56.             printf("\n");
  57.         }
  58.     }
  59.     else if (node->kind == AS_SIMPLE_NAME) {
  60.         printf("val     %s\n",namelist(node->links.val));
  61.     }
  62.     if (is_terminal_node(node->kind) || node == opt_node)
  63.         printf("span line: %d, span col: %d \n",
  64.             node->span.line,node->span.col);
  65. #ifdef TODO
  66.     -- else retrieve and print spans info.
  67. #endif
  68.         return;
  69. }
  70.  
  71. int zastcount(struct ast *node)                            /*;zastcount*/
  72. {
  73.     short i;
  74.  
  75.     i = 1;
  76.     while( i < MAX_AST ) {
  77.         if (node->links.subast[i] == NULL) return(i);
  78.         i++;
  79.     }
  80.     return(MAX_AST);
  81. }
  82.  
  83. void zpnlist(struct two_pool *listptr)                    /*;zpnlist*/
  84. {
  85.     /* dump list of pointers (to nodes) */
  86.     struct two_pool *bottom;
  87.     if (listptr == NULL) {
  88.         printf("null list\n");
  89.         return;
  90.     }
  91.     else {
  92.         bottom = listptr;
  93.         do {
  94.             listptr = listptr->link;
  95.             printf("0x%x ",listptr->val.node);
  96.         } while (listptr != bottom);
  97.     }
  98. }
  99.  
  100. /* Getlabels: Return the list of labels corresponding to a given node. If
  101.    The map is not defined for a node, NULL is returned. */
  102.  
  103. /* this function is defined as dump_labels in labels.c (nodestolabelstable) 
  104. zplabs(node)
  105. struct ast *node;
  106. {
  107.     struct labelsmap *tmp;
  108.     
  109.     for (tmp = nodetolabelstable[labelshash(node)]; tmp != NULL && 
  110.     tmp->node != node; tmp = tmp->link);
  111.     zpnlist(tmp->list);
  112. }
  113. */
  114.  
  115. void zprsstack(struct prsstack *p)                            /*;zprsstack*/
  116. {
  117.     /* dump contents (addresses) of parse stack */
  118.     while (p != NULL) {
  119.         printf("0x%x ",p);
  120.         p = p->prev;
  121.     }
  122.     printf("\n");
  123.  
  124. }
  125.  
  126. void zprssym(struct prsstack *p)                            /*;zprssym*/
  127. {
  128.     /* dump symbols of parse stack */
  129.     while (p != NULL) {
  130.         printf("%s ",TOKSTR(p->symbol));
  131.         p = p->prev;
  132.     }
  133.     printf("\n");
  134.  
  135. }
  136.  
  137. void zpstastack(struct two_pool *s)                            /*;zpstastack*/
  138. {
  139.     int        count = 0;
  140.     while (s != NULL)
  141.     {
  142.         count++ ;
  143.         printf ("%d %s", s -> val.state,
  144.             ( ((count%10) == 0) ? "\n":",") );
  145.         s = s -> link;
  146.     }
  147.     printf (" ======>size = %d<====== \n",count);
  148. }
  149.  
  150. void zprsnod(struct prsstack *p)                            /*;zprsnod*/
  151. {
  152.     /* dump an entry on the parse stack */
  153.     if (p == NULL)
  154.         printf("null pointer\n");
  155.     else if ISTOKEN(p) {
  156.         struct token *tok = p->ptr.token;
  157.  
  158.         printf("%s ",TOKSTR(p->symbol));
  159.         printf("%s\n",namelist(tok->index));
  160.         printf(" line %d  col %d \n",tok->loc.line, tok->loc.col);
  161.     }
  162.     else { /* ast node (nonterminal) */
  163.         printf("%s ",TOKSTR(p->symbol));
  164.         printf(" ast node: %d\n",p->ptr.ast);
  165.         if (p->ptr.ast != NULL)
  166.             zpnod(p->ptr.ast);
  167.     }
  168. }
  169.  
  170. void zdnstack(struct ast *dead)                            /*;zdnstack*/
  171. {
  172.     /* dump contents of dead node stack */
  173.     printf("Deadnode_Stack ");
  174.     while (dead != NULL) {
  175.         printf("0x%x ",dead);
  176.         dead = ((struct tmpnode *)dead)->link;
  177.     }
  178.     printf("End_of_Stack\n");
  179.  
  180. }
  181.  
  182. /*
  183.  * The text of kind_str that follows is generated by a spitbol program
  184.  */
  185. char *zkind_str(struct ast *node)                            /*;kind_str*/
  186. {
  187.     int as;
  188.  
  189.     static char *as_names[] = {
  190.         "pragma",
  191.         "arg",
  192.         "obj_decl",
  193.         "const_decl",
  194.         "num_decl",
  195.         "type_decl",
  196.         "subtype_decl",
  197.         "subtype_indic",
  198.         "derived_type",
  199.         "range",
  200.         "range_attribute",
  201.         "constraint",
  202.         "enum",
  203.         "int_type",
  204.         "float_type",
  205.         "fixed_type",
  206.         "digits",
  207.         "delta",
  208.         "array_type",
  209.         "box",
  210.         "subtype",
  211.         "record",
  212.         "component_list",
  213.         "field",
  214.         "discr_spec",
  215.         "variant_decl",
  216.         "variant_choices",
  217.         "string",
  218.         "simple_choice",
  219.         "range_choice",
  220.         "choice_unresolved",
  221.         "others_choice",
  222.         "access_type",
  223.         "incomplete_decl",
  224.         "declarations",
  225.         "labels",
  226.         "character_literal",
  227.         "simple_name",
  228.         "call_unresolved",
  229.         "selector",
  230.         "all",
  231.         "attribute",
  232.         "aggregate",
  233.         "parenthesis",
  234.         "choice_list",
  235.         "op",
  236.         "in",
  237.         "notin",
  238.         "un_op",
  239.         "int_literal",
  240.         "real_literal",
  241.         "string_literal",
  242.         "null",
  243.         "name",
  244.         "qualify",
  245.         "new_init",
  246.         "new",
  247.         "statements",
  248.         "statement",
  249.         "null_s",
  250.         "assignment",
  251.         "if",
  252.         "cond_statements",
  253.         "condition",
  254.         "case",
  255.         "case_statements",
  256.         "loop",
  257.         "while",
  258.         "for",
  259.         "forrev",
  260.         "block",
  261.         "exit",
  262.         "return",
  263.         "goto",
  264.         "subprogram_decl",
  265.         "procedure",
  266.         "function",
  267.         "operator",
  268.         "formal",
  269.         "mode",
  270.         "subprogram",
  271.         "call",
  272.         "package_spec",
  273.         "package_body",
  274.         "private_decl",
  275.         "use",
  276.         "rename_obj",
  277.         "rename_ex",
  278.         "rename_pack",
  279.         "rename_sub",
  280.         "task_spec",
  281.         "task_type_spec",
  282.         "task",
  283.         "entry",
  284.         "entry_family",
  285.         "accept",
  286.         "delay",
  287.         "selective_wait",
  288.         "guard",
  289.         "accept_alt",
  290.         "delay_alt",
  291.         "terminate_alt",
  292.         "conditional_entry_call",
  293.         "timed_entry_call",
  294.         "abort",
  295.         "unit",
  296.         "with_use_list",
  297.         "with",
  298.         "subprogram_stub",
  299.         "package_stub",
  300.         "task_stub",
  301.         "separate",
  302.         "exception",
  303.         "except_decl",
  304.         "handler",
  305.         "others",
  306.         "raise",
  307.         "generic_function",
  308.         "generic_procedure",
  309.         "generic_package",
  310.         "generic_formals",
  311.         "generic_obj",
  312.         "generic_type",
  313.         "gen_priv_type",
  314.         "generic_subp",
  315.         "generic",
  316.         "package_instance",
  317.         "function_instance",
  318.         "procedure_instance",
  319.         "instance",
  320.         "length_clause",
  321.         "enum_rep_clause",
  322.         "rec_rep_clause",
  323.         "compon_clause",
  324.         "address_clause",
  325.         "any_op",
  326.         "opt",
  327.         "list",
  328.         "range_expression",
  329.         "arg_assoc_list",
  330.         "private",
  331.         "limited_private",
  332.         "code",
  333.         "line_no",
  334.         "free",
  335.         0    };
  336.     as=node->kind;
  337.     return ( (as < 145) ? as_names[as] : "INVALID");
  338. }
  339. #endif
  340.